package com.klhappy.houyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.klhappy.houyuan.R;
import com.klhappy.houyuan.bean.DingDanBean.Hour;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by MrPu on 15/12/16.
 */
public class TimeAdapter extends BaseAdapter {

    private Context context;
    private List<Hour> hours;
    private int num;

    public TimeAdapter(Context context, List<Hour> hours) {
        this.context = context;
        this.hours = hours;
    }

    @Override
    public int getCount() {
        return hours.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHodler hodler = null;
        if (view == null){
            hodler = new ViewHodler();
            view = LayoutInflater.from(context).inflate(R.layout.item_time ,null);
            hodler.intView(view);
            view.setTag(hodler);
        }else {
            hodler = (ViewHodler) view.getTag();
        }

        hodler.morning.setText(hours.get(position).getAm());
        hodler.morning_tv.setText(hours.get(position).getPoint());
        hodler.morning.setTextColor(0xFF869e34);
        hodler.morning_tv.setTextColor(0xFF869e34);
        hodler.time_morning.setBackgroundColor(0xFFFFFFFF);
        if (num == position){
            hodler.time_morning.setBackgroundColor(0xFF869e34);
            hodler.morning.setTextColor(0xFFFFFFFF);
            hodler.morning_tv.setTextColor(0xFFFFFFFF);
        }
        return view;
    }

    class ViewHodler{
        @InjectView(R.id.morning)
        TextView morning;
        @InjectView(R.id.morning_tv)
        TextView morning_tv;
        @InjectView(R.id.time_morning)
        LinearLayout time_morning;

        public void intView(View view){
            ButterKnife.inject(this ,view);
        }
    }

    public void setNum(int num){
        this.num = num;
        notifyDataSetChanged();
    }
}
